﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ElingOA6_Admin_DSJCJ.Areas.Admin.Models;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.Common
{
    /// <summary>
    /// 视图中DataRow对象获取实体类
    /// </summary>
    public class ViewDataRowToModel
    {
        /// <summary>
        /// 获得文档对象列表(用于表格显示)
        /// </summary>
        public static List<DocumentGridModel> DataTableToListDocuemt(DataTable dt)
        {
            List<DocumentGridModel> modelList = new List<DocumentGridModel>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                DocumentGridModel model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = DataRowToModelDocument(dt.Rows[n]);
                    if (model != null)
                    {
                        modelList.Add(model);
                    }
                }
            }
            return modelList;
        }
        /// <summary>
        /// 得到一个文档对象实体(用于表格显示)
        /// </summary>
        private static DocumentGridModel DataRowToModelDocument(DataRow row)
        {
            DocumentGridModel model = new DocumentGridModel();
            if (row != null)
            {
                if (row["FDocId"] != null && row["FDocId"].ToString() != "")
                {
                    model.FDocId = decimal.Parse(row["FDocId"].ToString());
                }
                if (row["FDocClsCd"] != null)
                {
                    model.FDocClsCd = row["FDocClsCd"].ToString();
                }
                if (row.Table.Columns.Contains("FDocClsName"))
                {
                    if (row["FDocClsName"] != null)
                    {
                        model.FDocClsName = row["FDocClsName"].ToString();
                    }
                }
                if (row["FPubDate"] != null && row["FPubDate"].ToString() != "")
                {
                    model.FPubDate = DateTime.Parse(row["FPubDate"].ToString());
                }

                if (row.Table.Columns.Contains("FAuditDate"))
                {
                    if (row["FAuditDate"] != null && row["FAuditDate"].ToString() != "")
                    {
                        model.FAuditDate = DateTime.Parse(row["FAuditDate"].ToString());
                    }
                }
                if (row["FTitle"] != null)
                {
                    model.FTitle = row["FTitle"].ToString();
                }
                if (row.Table.Columns.Contains("FIsTop"))
                {
                    if (row["FIsTop"] != null && row["FIsTop"].ToString() != "")
                    {
                        model.FIsTop = int.Parse(row["FIsTop"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FStatus"))
                {
                    if (row["FStatus"] != null)
                    {
                        model.FStatus = row["FStatus"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FIsEnroll"))
                {
                    if (row["FIsEnroll"] != null)
                    {
                        model.FIsEnroll = row["FIsEnroll"].ToString();
                    }
                }
                if (row["FEmpName"] != null)
                {
                    model.FEmpName = row["FEmpName"].ToString();
                }
                if (row["FDeptName"] != null)
                {
                    model.FDeptName = row["FDeptName"].ToString();
                }
                if (row.Table.Columns.Contains("FStatus"))
                {
                    if (row["FIsNeedAudit"] != null)
                    {
                        model.FIsNeedAudit = row["FIsNeedAudit"].ToString();
                    }
                }
                if (row["FWorkGrpName"] != null)
                {
                    model.FWorkGrpName = row["FWorkGrpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelEmpName"))
                {
                    model.FDelEmpName = row["FDelEmpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelEmpName"))
                {
                    model.FDelEmpName = row["FDelEmpName"].ToString();
                }
                if (row.Table.Columns.Contains("FDelDate"))
                {
                    if (row["FDelDate"] != null && row["FDelDate"].ToString() != "")
                    {
                        model.FDelDate = DateTime.Parse(row["FDelDate"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FIsPubJCMS"))
                {
                    if (row["FIsPubJCMS"] != null)
                    {
                        model.FIsPubJCMS = row["FIsPubJCMS"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FIsReference"))
                {
                    if (row["FIsReference"] != null)
                    {
                        model.FIsReference = row["FIsReference"].ToString();
                    }
                }




                if (row.Table.Columns.Contains("FDisplayDate"))
                {
                    if (row["FDisplayDate"] != null && row["FDisplayDate"].ToString() != "")
                    {
                        model.FDisplayDate = DateTime.Parse(row["FDisplayDate"].ToString());
                    }
                }

                if (row.Table.Columns.Contains("FEditMode"))
                {
                    if (row["FEditMode"] != null)
                    {
                        model.FEditMode = row["FEditMode"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FTopSeq"))
                {
                    if (row["FTopSeq"] != null && row["FTopSeq"].ToString() != "")
                    {
                        model.FTopSeq = int.Parse(row["FTopSeq"].ToString());
                    }
                }
                if (row.Table.Columns.Contains("FThumbSrvFileName"))
                {
                    if (row["FThumbSrvFileName"] != null && row["FThumbSrvFileName"].ToString() != "")
                    {
                        model.FThumbSrvFileName = row["FThumbSrvFileName"].ToString();
                    }
                }





            }
            return model;
        }



    }
}
